#include "StateInfoView.h"

StateInfoView::StateInfoView(QWidget *parent) : QWidget(parent)
{
    this->setWindowFlags(Qt::WindowStaysOnTopHint);
    this->setWindowIcon(QIcon(":/QSS/image/Window_Icon.png"));
    this->setWindowTitle(tr("State Information"));
    MainLayout = new QGridLayout();
    treeWidget = new QTreeWidget();
    treeWidget->setHeaderHidden(true);

}

void StateInfoView::inputData(CState *StateInfo){
    treeWidget->clear();
    this->setLayout(MainLayout);
    treeWidget->setColumnCount(1);

    QList<QTreeWidgetItem *> *EventItems = new QList<QTreeWidgetItem *>();
    QTreeWidgetItem *rootStateItem = new QTreeWidgetItem();
    rootStateItem->setText(0,"State : "+StateInfo->getStateName());

    for(int i=0;i<StateInfo->getCount();i++){
        CEvent *mEvent = new CEvent();
        mEvent=StateInfo->getEvent(i);
        QTreeWidgetItem *EventItem = new QTreeWidgetItem(QStringList(mEvent->getEventName()));
        new QTreeWidgetItem(EventItem,QStringList("Event : "+mEvent->getEventName()));
        new QTreeWidgetItem(EventItem,QStringList("Description : "+mEvent->getEventDescription()));
        EventItems->append(EventItem);
    }
    rootStateItem->addChildren(*EventItems);


    treeWidget->addTopLevelItem(rootStateItem);
    treeWidget->setItemExpanded(rootStateItem,true);

   MainLayout->addWidget(treeWidget,0,0,1,1);

}
